
!
! Prvni uspesny pokus o vytvoreni jadra dobreho matching algoritmu.
!

module modzkus

  integer, parameter :: n = 3
  integer :: nvolani = 0
  integer :: a(n),b(n)
  logical :: volna(n)
  real :: x1(n), x2(n)

contains

recursive subroutine zkus(i)

  integer :: i,j,l
  real :: s,d

  nvolani = nvolani + 1

  do j = 1, n
     d = x2(j) - x1(i)
     if( volna(j) )then
           a(i) = j
           b(j) = i
           volna(j) = .false.
           if(  i < n )then
              call zkus(i+1)
           else
              s = sum((x2(a) - (x1 + d))**2,mask= .not. volna)
              write(*,*) (l,l=1,n)," -> ",a," :",s,d
           endif
           volna(j) = .true.
     endif
enddo

end subroutine zkus

end module modzkus


program zk

use modzkus

  x1 = (/ 0, 10, 20 /)
  x2 = (/20, 30, 10 /)

  volna = .true.

  call zkus(1)

  write(*,*) "pocet volani=",nvolani

end program zk

